MonotonicListValidator
Base classes
| Name |
Children |
Inherits |
Validator prettyqt.gui.validator
|
|
|
⋔ Inheritance diagram
graph TD
3817964565["validators.MonotonicListValidator"]
422589614["gui.Validator"]
1804432572["gui.ValidatorMixin"]
3227531497["core.ObjectMixin"]
2751680898["builtins.object"]
49520861["QtGui.QValidator"]
3984060476["QtCore.QObject"]
37984305["Shiboken.Object"]
422589614 --> 3817964565
1804432572 --> 422589614
3227531497 --> 1804432572
2751680898 --> 3227531497
49520861 --> 422589614
3984060476 --> 49520861
37984305 --> 3984060476
2751680898 --> 37984305
🛈 DocStrings
Bases: Validator
Validator which checks whether given string contains a monotonic list.
Source code in prettyqt/validators/monotoniclistvalidator.py
| class MonotonicListValidator(gui.Validator):
"""Validator which checks whether given string contains a monotonic list."""
ID = "monotonic"
def __init__(self, kind: str = "increasing", parent=None):
super().__init__(parent)
self._kind = kind
def __eq__(self, other: object):
return isinstance(other, MonotonicListValidator) and other._kind == self._kind
def validate(self, string: str, pos: int) -> tuple[gui.Validator.State, str, int]:
if self._kind != "increasing":
string = string[::-1]
for i, c in enumerate(string, start=1):
if c not in "+-., 0123456789":
return self.State.Invalid, string, i
if pos == len(string) >= 2 and string[-1] == " " and string[-2].isdigit(): # noqa: PLR2004
string = f"{string[:-1]}, "
pos += 1
prev = None
for valuestr in re_custom_sep.split(string.strip()):
try:
value = float(valuestr)
except ValueError:
return self.State.Intermediate, string, pos
if prev is not None and value <= prev:
return self.State.Intermediate, string, pos
prev = value
return self.State.Acceptable, string, pos
|
:fa-brands-github: Show source on GitHub